package com.rock.code.bigdata.kpicontrast.controller;

import com.rock.code.base.controller.BaseController;
import com.rock.code.bigdata.kpicontrast.service.KpiContrastService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * Created by SJ on 2019/1/8.
 */

@Controller
@RequestMapping("/kpiContrast")
public class KpiContrastController extends BaseController {

    @Resource
    private KpiContrastService KpiContrastServiceImpl;

    /**
     * 初始化加载页面
     *
     * @param kbpCode
     * @return
     */
    @RequestMapping("/{kbpCode}/{areaFlag}")
    public String initialize(@PathVariable("kbpCode") String kbpCode,
                             @PathVariable("areaFlag") String areaFlag) {
        this.request.setAttribute("kbpCode", kbpCode);
        this.request.setAttribute("areaFlag", areaFlag);
        return "bigdata/kpicontrast/kpiContrastView";
    }

    /**
     * 跳转3级页面
     *
     * @param extUnitId
     * @param kpiCode
     * @param timeHorizon
     * @return
     */
    @RequestMapping("/{extUnitId}/{kpiCode}/{timeHorizon}")
    public String contrastIframeView(@PathVariable("extUnitId") String extUnitId,
                                     @PathVariable("kpiCode") String kpiCode,
                                     @PathVariable("timeHorizon") String timeHorizon) {
        this.request.setAttribute("extUnitId", extUnitId);
        this.request.setAttribute("kpiCode", kpiCode);
        this.request.setAttribute("timeHorizon", timeHorizon);
        return "bigdata/kpicontrast/kpiAnalyzeView";
    }

    /**
     * 根据IP或名称查询资源
     *
     * @param DI_QU
     * @return
     */
    @ResponseBody
    @RequestMapping("/queryResouceByName")
    public List queryResouceByName(String DI_QU, String CI_TYPE) {
        try {
            return KpiContrastServiceImpl.queryResouceByName(DI_QU, CI_TYPE);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  null;
    }

    /**
     * 根据类别查询平台类数量
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("/queryResourceNumber")
    public HashMap queryResourceNumber(String kbpCodeStr, String areaFlag) {
        return KpiContrastServiceImpl.queryResourceNumber(kbpCodeStr, areaFlag);
    }

    /**
     * 按类资源的可用性
     *
     * @param kpiCode
     * @param kbpCode
     * @return
     */
    @ResponseBody
    @RequestMapping("/queryUsability")
    public HashMap queryUsability(String kpiCode, String kbpCode) {
        return KpiContrastServiceImpl.queryUsability(kpiCode, kbpCode);
    }

    /**
     * 按类资源的健康度
     * @param kbpCode
     * @param areaFlag
     * @return
     */
    @ResponseBody
    @RequestMapping("/queryHealth")
    public HashMap queryHealth(String kbpCode, String areaFlag) {
        return KpiContrastServiceImpl.queryHealth(kbpCode, areaFlag);
    }

    /**
     * 查询折线图
     *
     * @param extUnitId
     * @param kpiCode
     * @param timeHorizon
     * @return
     */
    @ResponseBody
    @RequestMapping("/queryKpiContrastInfo")
    public List queryKpiContrastInfo(String extUnitId, String kpiCode, String timeHorizon) {
        return KpiContrastServiceImpl.queryKpiContrastInfo(extUnitId, kpiCode, timeHorizon);
    }

    /**
     * 查询指标
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("/queryKpi")
    public List queryKpi(String extUnitId) {
        return KpiContrastServiceImpl.queryKpi(extUnitId);
    }
}
